﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ex03.GarageLogic
{
    public class Car : Vehicle
    {
        public enum eCarColor
        {
            DefaultValue = 0,
            PaleBlue,
            Silver,
            Black,
            White,
            Blue
        }

        public enum eDoorsAmount : byte
        { 
            DefaultValue = 0,
            TwoDoors = 2,
            ThreeDoors,
            FourDoors,
            FiveDoors
        }

        private eCarColor m_CarColor;
        private eDoorsAmount m_CarDoorsAmount;
        
        public Car(
            string i_CarModelName,
            string i_CarLicenseNumber,
            int i_CarWheelAmount,
            float i_CarWheelMaximumAirPressure,
            eCarColor i_CarColor, 
            eDoorsAmount i_CarDoorsAmount)
            : base(
            i_CarModelName,
            i_CarLicenseNumber,
            i_CarWheelAmount,
            i_CarWheelMaximumAirPressure)
        {
            if (!isCarColorLegal(i_CarColor))
            {
                ArgumentException CarColorError = new ArgumentException();

                throw CarColorError;
            }
            else if (!isCarDoorsAmountLegal(i_CarDoorsAmount))
            {
                ArgumentException CarDoorsAmountError = new ArgumentException();

                throw CarDoorsAmountError;
            }
            else
            {
                m_CarColor = i_CarColor;
                m_CarDoorsAmount = i_CarDoorsAmount;
            }
        }

        private bool isCarDoorsAmountLegal(eDoorsAmount i_CarDoorsAmountToCheck)
        {
            bool ReturnValue = false;

            switch (i_CarDoorsAmountToCheck)
            { 
                case eDoorsAmount.TwoDoors:
                case eDoorsAmount.ThreeDoors:
                case eDoorsAmount.FourDoors:
                case eDoorsAmount.FiveDoors:
                    ReturnValue = true;
                    break;
                case eDoorsAmount.DefaultValue:
                default:
                    break;
            }

            return ReturnValue;
        }

        private bool isCarColorLegal(eCarColor i_CarColorToCheck)
        {
            bool ReturnValue = false;

            switch (i_CarColorToCheck)
            {
                case eCarColor.Black:
                case eCarColor.Blue:
                case eCarColor.PaleBlue:
                case eCarColor.Silver:
                case eCarColor.White:
                    ReturnValue = true;
                    break;
                case eCarColor.DefaultValue:
                default:
                    break;
            }

            return ReturnValue;
        }

        public eCarColor CarColor
        {
            get { return m_CarColor; }
            set
            {
                if (!isCarColorLegal(value))
                {
                    ArgumentException CarColorError = new ArgumentException();

                    throw CarColorError;
                }
                else
                {
                    m_CarColor = value;
                }
            }
        }

        public eDoorsAmount CarDoorsAmount
        {
            get { return m_CarDoorsAmount; }
            set
            {
                if (!isCarDoorsAmountLegal(value))
                {
                    ArgumentException CarDoorsAmountError = new ArgumentException();

                    throw CarDoorsAmountError;
                }
                else
                {
                    m_CarDoorsAmount = value;
                }
            }
        }

        virtual public override bool AddPropulsionMaterial(
            EnergyType.eEnergyType i_PropulsionMaterialType,
            float i_PropulsionMaterialAmountToAdd)
        {
            throw new NotImplementedException();
        }

        //public override List<String> CollectQustionsListToAskUser()
        //{
        //    List<String> qustions = new List<String>();
            
        //    qustions = base.CollectQustionsListToAskUser();
        //    qustions.Add(String.Format("Enter Car Color {0}1. PaleBlue.{0}2. Silver.{0}3. Black.{0}4. White.{0}5. Blue.",Environment.NewLine));
        //    qustions.Add(String.Format("Enter Car Amout Of Doors (2,3,4,5):"));

        //    return qustions;
        //}

        //public override void GetStringsFromUserAndUpdateVehicleData(List<String> i_Answers)
        //{
        //    eCarColor carColorForTest = eCarColor.DefaultValue;
        //    eDoorsAmount doorsAmountForTest = eDoorsAmount.DefaultValue;

        //    base.GetStringsFromUserAndUpdateVehicleData(i_Answers);
        //    try
        //    {
        //        carColorForTest = (eCarColor)Enum.Parse(typeof(eCarColor), i_Answers[0]);
        //        if (Enum.IsDefined(typeof(eCarColor), carColorForTest))
        //        {
        //            CarColor = carColorForTest;
        //        }
        //        else
        //        {
        //            throw new FormatException("Error, Choose Currect Car Color, By it's Menu Number");
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception("Error, Choose Currect Car Color, By it's Menu Number", ex);
        //    }

        //    try
        //    {
        //        doorsAmountForTest = (eDoorsAmount)Enum.Parse(typeof(eDoorsAmount), i_Answers[1]);
        //        if (Enum.IsDefined(typeof(eDoorsAmount), doorsAmountForTest))
        //        {
        //            doorsAmountForTest = DoorsAmount;
        //        }
        //        else
        //        {
        //            throw new FormatException("Error, Choose Currect Car Door Amount, ");
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception("Error, Choose Currect Car Door Amount", ex);
        //    }
            
        //    finally
        //    {
        //        i_Answers.RemoveRange(0, 2);
        //    }
        //}

        //public override List<string> GetAllInformation()
        //{
        //    List<String> ReturnValue = null;
        //    ReturnValue = base.GetAllInformation();
        //    if (ReturnValue == null)
        //    {
        //        ReturnValue = new List<String>();
        //    }

        //    ReturnValue.Add(String.Format("Car Color: {0}", CarColor));
        //    ReturnValue.Add(String.Format("Car Number Of Doors: {0}", DoorsAmount));
        //    return ReturnValue;
        //}
    }
}
